<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<div>
    <md-progress-linear class="md-accent" md-mode="indeterminate" ng-if="vm.loading"></md-progress-linear>
    <card-layout body-css="md-padding" class="centered" ng-if="!vm.loading">
        <header-section>
            <div layout="row" layout-align="center start">
                <div class="card-title push-top-sm">Group Details</div>
                <span flex></span>
                <ng-md-icon icon="group" class="tc-accent" style="padding-right: 16px" size="30"></ng-md-icon>
            </div>
        </header-section>
        <body-section>
            <form name="groupForm">
                <vertical-section-layout section-title="Details" on-delete="vm.onDelete()" allow-delete="vm.canDelete()" on-save-edit="vm.onSave()" on-edit="vm.onEdit()" on-cancel-edit="vm.onCancel()"
                                         editable="vm.isEditable" is-valid="vm.isValid" allow-edit="vm.allowAdmin">
                    <readonly-section>
                        <div layout="row" class="layout-padding-bottom">
                            <span flex="25" class="property-name">Group Name</span>

                            <div flex>
                                {{vm.model.systemName}}
                            </div>
                        </div>
                        <div layout="row" class="layout-padding-top-bottom">
                            <span flex="25" class="property-name">Title</span>

                            <div flex>
                                {{vm.model.title}}
                            </div>
                        </div>
                        <div layout="row" class="layout-padding-top-bottom">
                            <span flex="25" class="property-name">Description</span>

                            <div flex>
                                {{vm.model.description}}
                            </div>
                        </div>
                    </readonly-section>
                    <editable-section>
                        <md-input-container class="md-block" ng-if="vm.model.systemName === null">
                            <label>Group Name</label>
                            <input name="systemName" type="text" ng-model="vm.editModel.systemName"/>
                            <div ng-messages="vm.$error" md-auto-hide="false">
                                <div ng-message="duplicateName">Group name is in use.</div>
                                <div ng-message="missingName">Group name is required.</div>
                            </div>
                        </md-input-container>
                        <div layout="row" class="layout-padding-top-bottom" ng-if="vm.model.systemName !== null">
                            <span flex="25" class="property-name">Group Name</span>

                            <div flex>
                                {{vm.editModel.systemName}}
                            </div>
                        </div>

                        <md-input-container class="md-block">
                            <label>Title</label>
                            <input ng-model="vm.editModel.title"/>
                        </md-input-container>

                        <md-input-container class="md-block">
                            <label>Description</label>
                            <input ng-model="vm.editModel.description"/>
                        </md-input-container>
                    </editable-section>
                </vertical-section-layout>
            </form>
            <vertical-section-layout section-title="Permissions" on-save-edit="vm.onSavePermissions()" on-edit="vm.onEditPermissions()" editable="vm.isPermissionsEditable"
                                     allow-edit="!vm.loading && vm.model.systemName !== null && vm.allowAdmin" ng-if="vm.groupId">
                <readonly-section class="pull-top">
                    <thinkbig-permissions-table allowed="vm.actions" read-only="true"></thinkbig-permissions-table>
                </readonly-section>
                <editable-section class="pull-top">
                    <thinkbig-permissions-table allowed="vm.editActions"></thinkbig-permissions-table>
                </editable-section>
            </vertical-section-layout>
            <vertical-section-layout allow-edit="false" show-vertical-check="true" section-title="Related Users" ng-if="vm.allowUsers" ng-if="vm.groupId">
                <readonly-section>
                    <md-list layout-fill class="list-item-table list-condensed md-dense" id="policy-list" ng-if="!vm.loading && vm.model.systemName !== null && vm.model.memberCount > 0">
                        <md-list-item>
                            <div layout="row" layout-fill>
                                <div flex="30" class="md-list-item-text hint">
                                    Display Name
                                </div>
                                <div flex="50" class="md-list-item-text hint">
                                    Email Address
                                </div>
                                <div flex="20" class="md-list-item-text hint">
                                    Active
                                </div>
                            </div>
                        </md-list-item>
                        <md-list-item ng-repeat="user in vm.users" class="hover">
                            <div layout="row" layout-fill ng-click="vm.onUserClick(user)">
                                <div flex="30" class="md-list-item-text overflow-hidden pad-right-md" style="text-overflow: ellipsis; white-space: nowrap">
                                    {{vm.getUserName(user)}}
                                </div>
                                <div flex="50" class="md-list-item-text overflow-hidden pad-right-md" style="text-overflow: ellipsis; white-space: nowrap">
                                    {{user.email}}
                                </div>
                                <div flex="20" class="md-list-item-text">
                                    <ng-md-icon icon="check" ng-if="user.enabled"></ng-md-icon>
                                </div>
                            </div>
                        </md-list-item>
                    </md-list>
                    <div ng-if="vm.loading || vm.model.systemName === null || vm.model.memberCount === 0">
                        No users in group.
                    </div>
                </readonly-section>
            </vertical-section-layout>
        </body-section>
    </card-layout>
</div>
